/*
 * Copyright 2009-2013 by KLSoft Corp.,
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of KLSoft Corp. ("Confidential Information").
 */
package ma.dev.sowondejong.util;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.telephony.SmsManager;
import android.widget.Toast;

/**
 * 1. FileName	: SMSUtil.java
 * 2. Package	: ma.dev.sowondejong.util
 * 3. Comments	:	
 * 4. Author	: kyoung wook
 * 5. DateTime	: 2013. 12. 15. 오후 7:43:15
 * 6. History	:
 * -----------------------------------------------------------------
 *	Date		 |	Name			|	Comment
 * -------------  -----------------   ------------------------------
 * 2013. 12. 15.		 | kyoung wook			|	최초작성
 * -----------------------------------------------------------------
 */

public class SMSUtil {

	private final Activity activity;

	public SMSUtil(Activity activity) {
		this.activity = activity;
	}

	public void sendSMS(String phoneNumber, String message, String url){

		SmsManager sms = SmsManager.getDefault();

		if(StringUtil.isEmptyString(message) || StringUtil.isEmptyString(phoneNumber)) {
			Toast.makeText(SowonDejonApp.getContext(), "전송할 상대방 정보에 문제가 있습니다.", Toast.LENGTH_SHORT).show();
			return;
		}

		try {
			message += " " + url;
			PendingIntent piSent = PendingIntent.getBroadcast(activity, 0, new Intent("SMS_SENT"), 0);
			PendingIntent piDelivered = PendingIntent.getBroadcast(activity, 0, new Intent("SMS_DELIVERED"), 0);
			sms.sendTextMessage(phoneNumber, null, message, piSent, piDelivered);
			
		} catch(NullPointerException e) {
			sms.sendTextMessage(phoneNumber, null, message, null, null);
			e.printStackTrace();
		}

	}

	public void sendMMS(Uri uri, String phoneNumber, String message) {
		uri = Uri.parse(""+uri);   
		Intent it = new Intent(Intent.ACTION_SEND);  
		it.putExtra("address", phoneNumber);
		it.putExtra("sms_body", message);   
		it.putExtra(Intent.EXTRA_STREAM, uri);   
		it.setType("image/*");
		activity.startActivity(it); 

	}



}
